from UI.pyse import Pyse
import time
# class BasicPage(object):
#     def __init__(self):
#         self.pyse = Pyse('chrome')
#     def open(self):
#         self.pyse.open('http://172.20.20.7:8091')
#     def quit(self):
#         self.pyse.quit()
#
# class LoginPage(BasicPage):
#     def sendUsername(self):
#         #https://blog.csdn.net/hou_angela/article/details/80305828 参考
#         tmp = 'xpath=>//input[@class="el-input__inner" and @tabindex="1"]'
#         self.pyse.type(tmp,'99zjr')
#     def sendPasswd(self):
#         pw = 'xpath=>//input[@class="el-input__inner" and @tabindex="2"]'
#         self.pyse.type(pw,'111111-a')
#     def clickLogin(self):
#         btLogin = 'xpath=>//div[@class="login-btn"]/button[@class="el-button el-button--primary el-button--small"]'
#         self.pyse.click(btLogin)


class BasicPage(object):
    def __init__(self):
        self.pyse = Pyse('chrome')
    def open(self):
        self.pyse.open('http://172.28.30.2:19090/creditplatformweb/login')
    def quit(self):
        self.pyse.quit()

class LoginPage(BasicPage):
    def sendUsername(self):
        #https://blog.csdn.net/hou_angela/article/details/80305828 参考
        tmp = 'css=>#username'
        self.pyse.type(tmp,'zjr')
    def sendPasswd(self):
        pw = 'css=>#password'
        self.pyse.type(pw,'111111-aA')
    def clickLogin(self):
        btLogin = 'css=>#submit'
        self.pyse.click(btLogin)
class User(LoginPage):
    def system(self):
        xpath = 'xpath=>//a[@id="10000000"]'
        self.pyse.click(xpath)
    def user_menu(self):
        xpath = 'css=>a[lay-href="systemUser/userTab"]'
        self.pyse.click(xpath)
    def iframe1(self):
        css = 'css=>iframe[src="systemUser/userTab"]'
        self.pyse.switch_to_frame(css)
    def checkbox(self):
        xpath = 'xpath=>//tr[1]//td[1]//div[1]//div[1]//i[1]'
        self.pyse.click(xpath)
    def update(self):
        xpath = "xpath=>//a[@class='updateBtn']"
        self.pyse.click(xpath)
    # def quite_iframe1(self):
    #     self.pyse.switch_to_frame_out()

    def close2(self):
        xpath = "xpath=>//a[@class='layui-layer-ico layui-layer-close layui-layer-close2']"
        self.pyse.click(xpath)
class OrgPage(LoginPage):
    def system(self):
        xpath = 'xpath=>//a[@id="10000000"]'
        self.pyse.click(xpath)
    def org(self):
        css = 'css=>a[lay-tips="机构管理"]'
        self.pyse.click(css)
    def iframe_org(self):
        css = 'xpath=>//iframe[@src="systemOrg/list" and @class="layadmin-iframe" and @frameborder="0"]'
        self.pyse.switch_to_frame(css)
    def click_org(self):
        css = 'css=>#orgTree_1_span'
        self.pyse.click(css)
    def get_org(self):
        js = "return document.getElementsByName('orgId')[0].value;"
        res = self.pyse.js(js)
        # # js = 'return 1;'
        # res = driver.execute_script(js)
        print(res)


if __name__=='__main__':
    page = OrgPage()
    page.open()
    page.sendUsername()
    page.sendPasswd()
    page.clickLogin()
    page.system()
    page.org()
    page.iframe_org()
    page.click_org()
    page.get_org()

    # from selenium import webdriver
    # import time
    # driver = webdriver.Chrome()
    # driver.get('http://172.28.30.2:19090/creditplatformweb/login')
    # driver.maximize_window()
    # driver.find_element_by_css_selector('#username').send_keys('zjr')
    # driver.find_element_by_css_selector('#password').send_keys('111111-aA')
    # driver.find_element_by_css_selector('#submit').click()
    # time.sleep(2)
    # driver.find_element_by_xpath('//a[@id="10000000"]').click()
    # time.sleep(2)
    # driver.find_element_by_css_selector('a[lay-tips="机构管理"]').click()
    # time.sleep(2)
    # iframe = driver.find_element_by_xpath('//iframe[@src="systemOrg/list" and @class="layadmin-iframe" and @frameborder="0"]')
    # driver.switch_to.frame(iframe)
    # driver.find_element_by_id('orgTree_1_span').click()
    # js = "return document.getElementsByName('orgId')[0].value;"
    # res = driver.execute_script(js)
    # print(res)





        # js = "return document.getElementsByName('orgId')[0].value;"
        # # res = self.pyse.js(js)
        # # js = 'return 1;'
        # res = driver.execute_script(js)
        # print(res)


        # driver.quit()